package chat.client;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Encryption_func {
	private StringBuffer buf_encryption=new StringBuffer("");
	Encryption_func(String kind,String text)
	{
		try {
			MessageDigest encryption=MessageDigest.getInstance(kind);
			encryption.update(text.getBytes());
			byte [] byte_encryption=encryption.digest();
			for(int i=0;i<byte_encryption.length;++i)
			{
				int temp=byte_encryption[i];
				if(temp<0)
					temp+=256;
				if(temp<16)
					buf_encryption.append("0");
				buf_encryption.append(Integer.toHexString(temp));
			}
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public String get_16()
	{
		return buf_encryption.toString().substring(8,24);
	}
	public String get_32()
	{
		return buf_encryption.toString();
	}
	public String get_sha()
	{
		return buf_encryption.toString();
	}
}
